package five.philosophers;

import java.util.concurrent.Semaphore;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author mateusz.ledzewicz
 */
public class Fork{
    private int id;
    private Semaphore sem = new Semaphore(1);
    public Fork(int id){
        this.id=id;
    }
    
    public String toString(){
        return "Fork " + this.id;
    }
    
    public Semaphore getSemaphor(){
        return sem;
    }
    
    public synchronized void  lift() throws InterruptedException{
        sem.acquire();
    }
    
    public void  put() {
        sem.release();
    }
    
   
}
